package com.project.pojo;

import com.project.common.DateUtil;
import lombok.Data;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Data
public class User {
    private Integer id;

    private String username;

    private String password;

    private String realName;

    private String sex;

    private Integer age;

    private String address;

    private String grade;

    private String headImage;

    private Date schoolTime;

    private String token;

    private int role;

    /**
     * 对象转HashMap
     * @return
     */
    public Map<String,String> toMap(){
        Map<String,String> map = new HashMap<>();
        map.put("id",this.id+"");
        map.put("username",this.username);
        map.put("realName",this.realName);
        map.put("sex",this.sex);
        map.put("age",this.age+"");
        map.put("address",this.address);
        map.put("grade",this.grade);
        map.put("token",this.token);
        map.put("headImage",this.headImage);
        map.put("role",this.role+"");
        map.put("schoolTime",DateUtil.dateFormat(this.schoolTime));
        return map;
    }

    /**
     * map转User对象
     * @param map
     * @return
     */
    public static User fromMap(Map<String,String> map){
        User user = new User();
        user.setId(Integer.parseInt(map.get("id")));
        user.setUsername(map.get("username"));
        user.setRealName(map.get("realName"));
        user.setSex(map.get("sex"));
        user.setAddress(map.get("address"));
        user.setGrade(map.get("grade"));
        user.setHeadImage(map.get("headImage"));
        user.setToken(map.get("token"));
        user.setRole(Integer.parseInt(map.get("role")));
        user.setSchoolTime(DateUtil.dateFormat(map.get("schoolTime")));
        return user;
    }



    public User(Integer id, String username, String realName,String password,String sex, Integer age, String address, String grade, String headImage,Date schoolTime) {
        this.id = id;
        this.username = username;
        this.realName = realName;
        this.password = password;
        this.sex = sex;
        this.age = age;
        this.address = address;
        this.grade = grade;
        this.headImage = headImage;
        this.schoolTime = schoolTime;
    }

    public User() {
    }
}